package com.lemon.smartsafety.view.grid;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.lemon.smartsafety.R;

/**
 * Created by Cooliean on 16/1/18.
 */
public class NoScrollableGridView extends GridView {
    private Context mContext;
    private View mEmptyView;

    public NoScrollableGridView(Context context) {
        super(context);
        this.mContext = context;
    }

    public NoScrollableGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
    }

    public NoScrollableGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mContext = context;
    }


    /**
     * 设置不滚动
     */
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

    }

    /**
     * 设置没有内容时候的视图
     */
    public void enableEmptyView() {
        mEmptyView = LayoutInflater.from(this.mContext).inflate(R.layout.item_empty_view, null);
        ((ViewGroup) this.getParent()).addView(mEmptyView);
        this.setEmptyView(mEmptyView);
    }

    public void disEnableEmptyView() {
        if (this.getEmptyView() != null) {
            this.removeView(this.getEmptyView());
        }
    }
}
